<?php 
	namespace app\admin\controller;
	use think\Controller;
	use think\Session;
	use think\Db;
    use think\Config;
    use think\Validate;


	//监控日志
	class Jklog extends Allow
	{   
        //加载日志列表
		public function getIndex()
		{
            $request=request();
            //关键字查询
            $a=$request->param('palias');
            $n=$request->param('pname');
            $e=$request->param('errnum');

            //查询数据分配至列表页面
	        $data=Db::table("jklog")->where('palias',"like","%".$a."%")->where('pname',"like","%".$n."%")->paginate(10);
			return $this->fetch('jklog/index',['data'=>$data]);
		}



        //执行修改
		public function getUpdates()
		{

			//创建请求对象
            $request=request();

            // 获取页面所传递的日志表id
            $id=$request->param('lid');
	        $data=Db::table("jklog")->where('lid',$id)->select();
            //设置修改后的字段数据
            $data['lnotify']='已发送';

            //执行修改操作
            if(Db::table('jklog')->where('lid',"{$id}")->update($data))
        	{
                $data=$data['0'];
                //查询设置表中最新数据
                $set=Db::table('set')->order('sid desc')->limit(1)->find();
                //获取手机号数据
                $nnum=$set['notifyphone'];
                //调用发送短信功能
                sendNote($nnum);
                //调用发送邮件功能
                $notifymail=$set['notifymail'];
                $mail=explode(',',$notifymail);
                $pname=$data['pname'];
                $title="您所管理的".$pname.'发生了以下错误';
                $errnum=$data['errnum'];
                $econtent=$data['econtent'];
                $content="【错误编码:".$errnum."】\n错误描述：".$econtent;
                foreach ($mail as $key => $to){
                    sendMail($to,$title,$content);
                }
              
        		$this->success('通知成功','/jklog/index');
                //成不成功都返回错误日志列表
        	}else{
                $data['lnotify']='未发送';
                Db::table('jklog')->where('lid',"{$id}")->update($data);

        		$this->error('通知失败','/jklog/index');
        	}

		}

	}
 ?>